{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 标准数据类型\n",
    "### 1、三个不可变数据：\n",
    "#### Number(数字)、String(字符串)、Tuple(元组)\n",
    "### 2、三个可变数据：\n",
    "#### List(列表)、Dictionary(字典)、Set(集合)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (一)Number\n",
    "### 浮点数=小数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (二)布尔值\n",
    "### 只有两种可能的值：Ture or False\n",
    "### 例子：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "is_open = True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (三)字符串\n",
    "### 包含汉子、英文字母、空格、数字等等\n",
    "## 1、字符串的表示\n",
    "### 字符串应放在引号中间\n",
    "### 例子(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I love you.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 例子(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "你好：\n",
      "   I love you.\n",
      "TT\n",
      "\n"
     ]
    }
   ],
   "source": [
    "email_message = \"\"\"\n",
    "你好：\n",
    "   I love you.\n",
    "TT\n",
    "\"\"\"\n",
    "print(email_message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、获取字符串的长度\n",
    "### 运用内置函数lenth(len)\n",
    "### 例子：(注：长度包括空格)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love 天天\"\n",
    "print(len(course_name))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、访问字符串的某个字符\n",
    "### 用0表示从左向右数第一字符的索引,此后用1、2、3、4等访问后续字符\n",
    "### 用-1表示从右向左数第一字符的索引，此后用-2、-3、-4、-5等访问后续字符\n",
    "### 使用[]\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I\n",
      "天\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love 天天\"\n",
    "print(course_name[0])\n",
    "print(course_name[-2])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、访问字符串中的某段字符\n",
    "### 使用[],并用：来表示范围\n",
    "### 例子：(注：冒号后对应的字符不会被显示出来)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " lo\n",
      " love 天天\n",
      "I lo\n",
      "I love 天天\n",
      " lov\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love 天天\"\n",
    "print(course_name[1:4])\n",
    "print(course_name[1:])\n",
    "print(course_name[:4])\n",
    "print(course_name[:])\n",
    "print(course_name[1:-4])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4、转义字符(Escape Charactors)\n",
    "### (1)\\\":在字符串里显示双引号\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I love \"TT\".\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love \\\"TT\\\".\"\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (2)\\':在字符串里显示单引号\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I love 'TT'.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love \\'TT\\'.\"\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (3)\\n:实现换行效果\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I love \n",
      "TT.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love \\nTT.\"\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 5、占位符\n",
    "### {}:可往里输入任意内容\n",
    "### 例子见f-string函数中"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 6、f-string函数\n",
    "### 生成内容动态变幻的字符串\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "祝LaLaLa中秋节快乐！\n"
     ]
    }
   ],
   "source": [
    "friend_name = \"LaLaLa\"\n",
    "festivel = \"中秋节\"\n",
    "congrats_message = f\"祝{friend_name}{festivel}快乐！\"\n",
    "print(congrats_message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 7、常用字符串函数\n",
    "### 对象后加.即可调用自己的函数\n",
    "### (1)upper函数\n",
    "### 将所有字母转化为大写\n",
    "### 例子：(注：原有字符串不受影响)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I LOVE YOU.\n",
      "I love you.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(course_name.upper())\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (2)lower函数\n",
    "### 将所有字母转化为小写\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i love you.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(course_name.lower())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (3)strip函数\n",
    "### 用来删除字符串开头或结尾的空格\n",
    "### 例子：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nice to meet you.\n",
      "  Nice to meet you.  \n"
     ]
    }
   ],
   "source": [
    "course_name = \"  Nice to meet you.  \"\n",
    "print(course_name.strip())\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (4)lstrip函数\n",
    "### 用来删除字符串开头的空格\n",
    "### 例子：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Nice to meet you.  \n",
      "  Nice to meet you.  \n"
     ]
    }
   ],
   "source": [
    "course_name = \"  Nice to meet you.  \"\n",
    "print(course_name.lstrip())\n",
    "print(course_name)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (4)rstrip函数\n",
    "### 用来删除字符串结尾的空格\n",
    "### (5)find函数\n",
    "### 在字符串中查找单个字符或字符序列\n",
    "### 例子：(注：1、没有对应字符会显示-1。2、重复出现的字符只能查找首个)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(course_name.find(\"Love\"))\n",
    "print(course_name.find(\"love\"))\n",
    "print(course_name.find(\"o\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (6)replace函数\n",
    "### 在字符串中查找一个字符或字符序列，并替换成你想要的内容\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I hate you.\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(course_name.replace(\"love\",\"hate\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (7)in函数\n",
    "### 检查是否存在某字符\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "course_name = \"I love you.\"\n",
    "print(\"love\"in course_name)\n",
    "print(\"hate\"in course_name)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (8)startswith函数\n",
    "### 用来判断字符串开头是否是某字符\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "course_name = \"Everyone love you.\"\n",
    "print(course_name.startswith(\"Eve\"))\n",
    "print(course_name.startswith(\"No\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (9)endswith函数\n",
    "### 用来判断字符串结尾是否是某字符\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n"
     ]
    }
   ],
   "source": [
    "course_name = \"Everyone love you.\"\n",
    "print(course_name.endswith(\"you.\"))\n",
    "print(course_name.endswith(\"you\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (10)split函数\n",
    "### 将一段字符串切成若干个子字符串\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Everyone', 'love', 'you.']\n",
      "['Every', 'ne l', 've y', 'u.']\n",
      "['Everyone love you.']\n"
     ]
    }
   ],
   "source": [
    "course_name = \"Everyone love you.\"\n",
    "print(course_name.split(\" \"))\n",
    "print(course_name.split(\"o\"))\n",
    "print(course_name.split(\"1\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# (四) 基础数学运算\n",
    "## (1) 加减乘除\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "-2\n",
      "6\n",
      "0.6666666666666666\n",
      "0\n",
      "2\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "print(2+3)\n",
    "print(2-4)\n",
    "print(2*3)\n",
    "print(2/3)\n",
    "print(2//3)\n",
    "print(2%3)\n",
    "print(2**3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## (2) 增强赋值运算符\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "x=2\n",
    "x=x+3\n",
    "x+=3\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# （一）List\n",
    "### 按顺序排列的一组数据(可以是任何类型数据)\n",
    "## 1、列表的表示\n",
    "### (1)第一种表示方式\n",
    "### 用[]表示，如[元素0,元素1,元素2]\n",
    "### 例子：\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[]\n",
      "['a', 'b', 'c', 'd']\n",
      "['Anna', 'Jake', 'Bob']\n",
      "[1, 2, 3, 4]\n",
      "[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
     ]
    }
   ],
   "source": [
    "filenames = []\n",
    "letters = [\"a\",\"b\",\"c\",\"d\"]\n",
    "names = [\"Anna\",\"Jake\",\"Bob\"]\n",
    "numbers = [1,2,3,4]\n",
    "zeros = [0] * 100\n",
    "print(filenames)\n",
    "print(letters)\n",
    "print(names)\n",
    "print(numbers)\n",
    "print(zeros)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### (2)第二种表示方式\n",
    "### 例子1："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n"
     ]
    }
   ],
   "source": [
    "numbers_from_range = list(range(15))\n",
    "print(numbers_from_range)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 例子2:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['w', 'o', 'a', 'i', 't', 't']\n"
     ]
    }
   ],
   "source": [
    "chars = list(\"woaitt\")\n",
    "print(chars)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、列表的运算\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'b', 'c', 'd', 1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "letters = [\"a\",\"b\",\"c\",\"d\"]\n",
    "numbers = [1,2,3,4]\n",
    "concatenated = letters + numbers\n",
    "print(concatenated)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、数阵\n",
    "### 列表的列表\n",
    "### 例子："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 2, 3], [4, 5, 6]]\n"
     ]
    }
   ],
   "source": [
    "matrix = [[1,2,3],[4,5,6]]\n",
    "print(matrix)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Miniconda使用说明\n",
    "环境列表：conda env list  \n",
    "建立环境：conda create --name python38 python=3.8      \n",
    "激活环境：conda activate python38   \n",
    "退出环境：conda deactivate   \n",
    "\n",
    "更新conda：conda update -n base -c defaults conda   \n",
    "版本显示：conda -V   \n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
